package com.example.base.flow.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.base.excetion.GlobalExcetion;
import com.example.base.flow.domain.SysFlowInstance;
import com.example.base.flow.mapper.SysFlowInstanceMapper;
import com.example.base.flow.service.SysFlowInstanceService;
import org.springframework.stereotype.Service;
import org.springframework.cache.annotation.*;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.cache.annotation.CacheConfig;

import java.io.Serializable;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author X.I.O
 * @since 2024-05-17
 */
@Service
@Transactional
@CacheConfig(cacheNames = "SysFlowInstanceServiceImpl")
public class SysFlowInstanceServiceImpl extends ServiceImpl<SysFlowInstanceMapper, SysFlowInstance> implements SysFlowInstanceService {

    @Cacheable(cacheNames = "sysflowinstance",key = "#id")
    @Override
    public SysFlowInstance getById(Serializable id){
        return super.getById(id);
    }

    @CacheEvict(cacheNames = "sysflowinstance", key = "#id")
    @Override
    public boolean removeById(Serializable id) {
        return super.removeById(id);
    }

    @CacheEvict(cacheNames = "sysflowinstance", key = "#sysflowinstance.id")
    @Override
    public boolean updateById(SysFlowInstance sysflowinstance) {
        return super.updateById(sysflowinstance);
    }

    @CachePut(cacheNames = "sysflowinstance", key = "#sysflowinstance.id")
    public SysFlowInstance saveSysFlowInstance(SysFlowInstance sysflowinstance) throws GlobalExcetion {
        super.save(sysflowinstance);
        return sysflowinstance;
    }

    @CacheEvict(cacheNames = "sysflowinstance", key = "#sysflowinstance.id")
    public SysFlowInstance updateSysFlowInstanceById(SysFlowInstance sysflowinstance) throws GlobalExcetion{
        super.updateById(sysflowinstance);
        return sysflowinstance;
    }




    public IPage<SysFlowInstance> page(Integer page, Integer pageSize) throws GlobalExcetion {
        LambdaQueryWrapper<SysFlowInstance> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        IPage<SysFlowInstance> iPage=super.baseMapper.selectPage(new Page<>(page,pageSize),lambdaQueryWrapper);
        return iPage;
    }
}
